<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/30
 * Time: 10:03
 */

namespace Home\Controller;


class OrderController extends HomeController{

    public function getRepairInfo(){
        $search_select = I('post.search_select');
        $info = I('post.info');
        if(!empty($search_select) && !empty($info)){
            $Order = M('Order');
            $Order->alias('ORDERS');
            $Order->join('pan_order_shop shop ON ORDERS.id = shop.id');
            if($search_select == 1){
                $result = M('Order')->where(array('phone'=>$info))->field('customer,repair_model,repair_status,repair_price,repair_handsel')->order('ORDERS.id desc')->limit(1)->select();
            }elseif($search_select == 2){
                $result = M('Order')->where(array('customer'=>$info))->field('customer,repair_model,repair_status,repair_price,repair_handsel')->order('ORDERS.id desc')->limit(1)->select();
            }
        }

        if(is_array($result) && !empty($result)){
            switch($result[0]['repair_status']){
                case 1: $result[0]['repair_status'] = '未维修';
                    break;
                case 2: $result[0]['repair_status'] = '正在维修';
                    break;
                case 3: $result[0]['repair_status'] = '已完成维修';
                    break;
                default:$result[0]['repair_status'] = '正在维修';
            }
        }
        echo json_encode($result);
    }
}